package com.example.xiaosuan.startproject_304fjl;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.xiaosuan.startproject_304fjl.jiantingqi.fangwenwangluo;
import com.example.xiaosuan.startproject_304fjl.lie.model1;
import com.example.xiaosuan.startproject_304fjl.lie.model2;
import com.example.xiaosuan.startproject_304fjl.lie.weatherInfo;

public class MainActivity extends AppCompatActivity implements View.OnClickListener,fangwenwangluo {
    protected EditText et1;
    protected Button bt1;
    protected Button bt2;
    protected TextView tv;
    protected TextView tv1;
    protected TextView tv2;
    protected TextView tv3;
    protected TextView tv4;
    protected TextView tv5;
    protected TextView tv6;
    protected TextView tv7;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();


    }
    private void init(){
        tv =(TextView) findViewById(R.id.textView41);
        tv1 =(TextView) findViewById(R.id.textView);
        tv2 =(TextView) findViewById(R.id.textView2);
        tv3 =(TextView) findViewById(R.id.textView3);
        tv4 =(TextView) findViewById(R.id.textView4);
        tv5 =(TextView) findViewById(R.id.textView5);
        tv6 =(TextView) findViewById(R.id.textView6);
        tv7 =(TextView) findViewById(R.id.textView7);
        bt1=( Button) findViewById(R.id.button7);
        bt1.setOnClickListener(this);
        bt2=( Button) findViewById(R.id.button);
        bt2.setOnClickListener(this);
        et1= (EditText) findViewById(R.id.editText4);
    }
    @Override
    public void onClick(View v) {

        switch (v.getId()) {
            case R.id.button7:
                model1 weatherModel = new model1();
                weatherModel.getWeather(et1.getText().toString(), this);
                break;
            case R.id.button:
                model2 weatherModel2 = new model2();
                weatherModel2.getWeather(et1.getText().toString(), this);
                break;
            default:
                break;
        }
    }

    @Override
    public void onResponse(weatherInfo weather) {
        if (weather != null) {
            tv1.setText(weather.getCity());
            tv2.setText(weather.getCityid());
            tv3.setText(weather.getTemp());
            tv4.setText(weather.getWD());
            tv5.setText(weather.getWS());
            tv6.setText(weather.getSD());
        } else {
            tv1.setText("未知");
        }

    }

    @Override
    public void onFail(String msg) {
        tv1.setText(msg);
    }
}
